<template>
	<view class="content">
		<view class="content_input">
			<view class="name">姓名</view>
			<view class="input">
				<input type="text" v-model="name" placeholder="请输入姓名"/>
			</view>
		</view>
		<view class="content_input">
			<view class="name">Email</view>
			<view class="input">
				<input type="text" v-model="email" placeholder="请输入邮箱"/>
			</view>
		</view>
		<view class="content_input">
			<view class="name">手机号</view>
			<view class="input">
				<input type="text" v-model="mobile" placeholder="请输入手机号"/>
			</view>
		</view>
		<view class="content_input">
			<view class="name">职位</view>
			<view class="input">
				<input type="text" v-model="postion" placeholder="请输入职位"/>
			</view>
		</view>
		<view class="content_input">
			<view class="name">公司名称</view>
			<view class="input">
				<input type="text" v-model="company" placeholder="请输入公司名称"/>
			</view>
		</view>
		<view class="content_input">
			<view class="name">图形验证码</view>
			<view class="input txyzm">
				<input type="text" v-model="validdate" placeholder="请输入图形验证码"/>
				<image mode="widthFix" class="yzm" @click="getCode" :src="'data:image/png;base64,'+imgCode"></image>
			</view>
		</view>
		<view class="content_input">
			<view class="name">短信验证码</view>
			<view class="input txyzm">
				<input type="text" v-model="MobileCode" placeholder="请输入短信验证码"/>
				<view class="getyzm" @tap="getWrap">{{iswrap?'获取验证码':`${wrapTime}秒重新获取`}}</view>
			</view>
		</view>
		<view class="content_bottom">
			<view class="content_bottom_box">
				<view class="button" @click="tijiao">
					提交信息
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		defineProps,
	} from 'vue'
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import {
		homeApi
	} from "@/api/index"
	import {link,formatRichText,isPhone,isEmail} from '@/utils/utils.js'
	const id = ref('')
	onLoad((open)=>{
		id.value = open.id
		getCode()
	})
	// 获取验证
	const imgCode = ref('')
	const validkey = ref('')
	const getCode = async()=>{
		let data = {
			do:"verifycode2",
			sizemode:2,
		}
		let res = await homeApi.publicGet(data)
		imgCode.value = res.columns[0].imagedata
		validkey.value = res.columns[0].validkey2
	}
	// 验证码倒计时
	const iswrap = ref(true)
	const wrapTime = ref(60)
	const validdate = ref('')
	const getWrap = () => {
		if (iswrap.value) {
			getTelCode()
		}
	}
	const mobile = ref('')
	const MobileCode = ref('')
	const getTelCode = async()=>{
		if(mobile.value==''){
			uni.showToast({
				title: '请输入手机号',
				icon:'none',
				duration: 2000
			});
			return
		}
		if(!isPhone(mobile.value)){
			uni.showToast({
				title: '请输入正确的手机号',
				icon:'none',
				duration: 2000
			});
			return
		}
		let data = {
			SendToPhone:mobile.value,
			validdate:validdate.value,
			validkey2:validkey.value
		}
		let res = await homeApi.publicPost(data,'sendmobilecode')
		if(res.columns[0].error_no=='0'){
			iswrap.value=false
			wrapTime.value=60
			uni.showToast({
				title:res.columns[0].error_msg,
				icon:'none',
				duration: 2000
			});
			const countdownId  = setInterval(()=>{
				if (wrapTime.value > 0) {
					wrapTime.value--;
				} else {
					clearInterval(countdownId);
					iswrap.value=true
				}
			},1000)
		}else{
			iswrap.value=true
			uni.showToast({
				title: res.columns[0].error_msg,
				icon:'none',
				duration: 2000
			});
		}
	}
	const name = ref('')
	const company = ref('')
	const email = ref('')
	const postion = ref('')
	const tijiao = async()=>{
		let data = {
			exhid:id.value,
			validkey2:validkey.value,
			validdatecode:validdate.value,
			name:name.value,
			company:company.value,
			email:email.value,
			postion:postion.value,
			mobile:mobile.value
		}
		let res = await homeApi.publicPost(data,'txlSaveEnterInfo')
		for (let i = 0; i < res.columns.length; i++) {
			if (res.columns[i].name == 'txlSaveEnterInfo') {
				if(res.columns[i].statuscode=='200'){
					uni.showToast({
						title: res.columns[i].message,
						icon: 'success',
						duration: 2000
					});
					setTimeout(() => {
						uni.navigateBack({
							delta:1
						})
					}, 2000)
				}else{
					uni.showToast({
						title: res.columns[i].message,
						icon: 'none',
						duration: 2000
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: calc(100% - 60rpx);
		padding:0 30rpx;
		&_title{
			width: 100%;
			height: 100rpx;
			display: flex;
			align-items: center;
			font-size: 32rpx;
			color: #999;
		}
		&_input{
			padding-top: 30rpx;
			padding-bottom: 30rpx;
			display: flex;
			align-items: center;
			border-bottom:1px solid #ebecf4;
			.name{
				width: 190rpx;
				font-size: 32rpx;
			}
			.input{
				display: flex;
				align-items: center;
				input{
					font-size: 32rpx;
				}
			}
			.txyzm{
				justify-content: space-between;
				input{
					font-size: 32rpx;
					width: calc(100% - 240rpx);
				}
				.yzm{
					width: 200rpx;
				}
				.getyzm{
					padding: 10rpx 20rpx;
					border: 1px solid #e94f06;
					border-radius: 30px;
					font-size: 30rpx;
					color: #e94f06;
				}
			}
		}
		&_bottom{
			width: 100%;
			height: 120rpx;
			&_box{
				width: 100%;
				height: 120rpx;
				position: fixed;
				bottom: 0;
				left: 0;
				display: flex;
				align-items: center;
				justify-content: center;
				.button{
					width: calc(100% - 60rpx);
					height: 80rpx;
					background: #e94f06;
					border-radius: 8px;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #fff;
					font-size: 32rpx;
				}
			}
		}
	}
</style>